package cn.edu.jxust.common.domain.web.api.sysresource;

import cn.edu.jxust.common.domain.dto.SysResourceVo;
import cn.edu.jxust.common.response.Result;
import cn.edu.jxust.core.infrastructure.util.Const;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import javax.validation.Valid;

/**
 * @author QiuKangming
 * @version 1.0
 * @description
 * @since 2020/09/15 15:14
 */
@RequestMapping("/api/authority")
public interface IAuthorityController {

    /**
     * 获取权限列表
     * @param roleId 角色id
     * @return Result
     */
    @GetMapping("/{roleId}")
    @RequiresPermissions("resource:list")
    Result getAuthorityList(@PathVariable(name = "roleId") Integer roleId);

    /**
     * 根据当前登录角色获取其所有权限信息
     * @param roleId 角色id号
     * @return Result
     */
    @RequiresRoles(Const.SUPER_ADMIN)
    @GetMapping("/list/{roleId}")
    @RequiresPermissions("resource:list")
    Result getCurrRoleAuthorityList(@PathVariable(name = "roleId") @Valid Integer roleId);

    /**
     * 增加权限
     * @param sysResourceVo 资源视图对象
     * @param result 绑定结果集
     * @return Result
     */
    @PostMapping
    @RequiresRoles(Const.SUPER_ADMIN)
    @RequiresPermissions("resource:add")
    Result addAuthc(@RequestBody @Validated SysResourceVo sysResourceVo, BindingResult result);

    /**
     * 根据 id 删除资源
     * @param id 资源id
     * @return Result
     */
    @DeleteMapping("/{id}")
    @RequiresRoles(Const.SUPER_ADMIN)
    @RequiresPermissions("resource:del")
    Result delAuthc(@PathVariable("id") Integer id);

    /**
     * 修改权限信息
     * @param sysResourceVo 资源视图对象
     * @param result 绑定结果集
     * @return Result
     */
    @PutMapping
    @RequiresRoles(Const.SUPER_ADMIN)
    @RequiresPermissions("resource:edit")
    Result modifyAuthc(@RequestBody @Validated SysResourceVo sysResourceVo, BindingResult result);

    /**
     * 获取父权限的权限树
     * @return Result
     */
    @GetMapping("/parent")
    @RequiresRoles(Const.SUPER_ADMIN)
    @RequiresPermissions("resource:list")
    Result getParentAuthc();
}
